﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetfractionHub.Network.Protocol;
using NetfractionHub.Network.Protocol.BASE.Factory;

namespace NetfractionHub.LocalMachine.BotCommands.Handler
{
    [CommandHandler("uptime")]
    public class Uptime : CommandHandler
    {
        public override BotReturnStatus HandleCommandMessage(NetfractionHub.RemoteMachine.Node source, CommandMessage message)
        {
            if (!Security.Permission.HasPermission(source.SecurityIdentity, typeof(Security.Permissions.CheckUptimePermission)))
                return new BotReturnStatus(false, Security.Permission.GetDeniedString(typeof(Security.Permissions.CheckUptimePermission)));

            TimeSpan uptime = DateTime.Now.Subtract(Network.ConnectionManager.Hub.StartTime);
            return new BotReturnStatus(true, string.Format("{0} days, {1} hours, {2} minutes, {3} seconds", uptime.Days, uptime.Hours, uptime.Minutes, uptime.Seconds));
        }
    }
}
